package com.datn.DataAccess;

import java.io.IOException;
import java.util.ArrayList;

import com.datn.utils.AlertCustom;
import com.datn.utils.FileUtils;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class SQLiteTest {
		
	private Context mContext;
	private static final String DATABASE_NAME = "NearLocationData";
	private static final String DATABASE_TABLE = "tblAccount";
	private static final int DATABASE_VERSION = 2;
	
	public SQLiteTest(Context context) {
			// TODO Auto-generated constructor stub
			mContext=context;
		}
	
	public void openOrCreateDatabase(){
		SQLiteDatabase db=mContext.openOrCreateDatabase(DATABASE_NAME, SQLiteDatabase.CREATE_IF_NECESSARY, null);
		FileUtils file=new FileUtils(mContext);
       
        try {
			ArrayList<String> allLine= file.readDatabase();
			for (int i = 0; i < allLine.size(); i++) {
				db.execSQL(allLine.get(i));
			}
			
			Cursor c = db.rawQuery("SELECT * FROM tblAccount", null);
	    	StringBuilder sb=new StringBuilder();
	    	if (c != null ) {
	    		if  (c.moveToFirst()) {
	    			do {
	    				String stUsername = c.getString(c.getColumnIndex("Username"));
	    				String stPassword = c.getString(c.getColumnIndex("Password"));
	    				sb.append("User:"+stUsername+" Pass:"+stPassword);
	    			}while (c.moveToNext());
	    		} 
	    	}
	    	  	
	    	AlertCustom.showAlert(mContext, "Data", sb.toString());
	    	
	    	db.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
		
		
}
